package pers.yd.springbootmvc.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import pers.yd.springbootmvc.dto.Movies;

import java.util.List;

/**
 * @author yudi
 */
@Repository
public interface MoviesDao extends ElasticsearchRepository<Movies, String> {
    Page<Movies> findByTitle(String title, Pageable pageable);

    Page<Movies> findByTitleAndGenre(String title, String genre, Pageable pageable);

    Page<Movies> findByTitleIn(List<String> titles, Pageable pageable);

    Page<Movies> findByTitleAndYearBetween(String title, long begin, long end, Pageable pageable);

    @Query("{\"bool\": {\n" +
            "      \"must\": [\n" +
            "        {\n" +
            "          \"query_string\": {\n" +
            "            \"query\": \"?0\",\n" +
            "            \"default_operator\": \"or\"\n" +
            "          }\n" +
            "        },\n" +
            "        {\n" +
            "          \"match\": {\n" +
            "            \"genre\": \"?1\"\n" +
            "          }\n" +
            "        }\n" +
            "      ]\n" +
            "    }" +
            "}")
    List<Movies> get(String title, String genre);

}
